import baseUrl from "./baseUrl"

var obj = {
  get(url,data){
    return new Promise((resolve,rejected)=>{
      uni.request({
        url: baseUrl+url,
        data:data,
        success(res){
          resolve(res);  
        },
        fail(res){
          resolve(res);
        }
      })
    })
  },

  post(url,data){
    return new Promise((resolve,rejected)=>{
      uni.request({
        url: baseUrl+url,
        method:"POST",
        header:{
          'content-type':"application/x-www-form-urlencoded"
        },
        data:data,
        success(res){
          resolve(res);  
        },
        fail(res){
          resolve(res);
        }
      })
    })
  }
}

function http(config){
  if(config.method){
	  if(config.method.toLowerCase() == "post"){
		  return obj.post(config.url,config.data)
	  }
  }else{
    return obj.get(config.url,config.data)
  }
}


export default obj;
export{
  http
}